﻿
namespace NetROS.Tiers.Windows.Forms
{
	/// <summary>
	/// abstract RazdobljeStopa typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class RazdobljeStopaDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<RazdobljeStopaDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.RazdobljeStopa _currentRazdobljeStopa = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxRazdobljeStopaDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxRazdobljeStopaErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxRazdobljeStopaBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the ID property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIDDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the DatumOd property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxDatumOdDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the DatumDo property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxDatumDoDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Stopa property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxStopaDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.RazdobljeStopa> _RazdobljeStopaList;
				
		/// <summary> 
		/// The list of RazdobljeStopa to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.RazdobljeStopa> RazdobljeStopaList
		{
			get {return this._RazdobljeStopaList;}
			set
			{
				this._RazdobljeStopaList = value;
				this.uxRazdobljeStopaBindingSource.DataSource = null;
				this.uxRazdobljeStopaBindingSource.DataSource = value;
				this.uxRazdobljeStopaDataGridView.DataSource = null;
				this.uxRazdobljeStopaDataGridView.DataSource = this.uxRazdobljeStopaBindingSource;				
				//this.uxRazdobljeStopaBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxRazdobljeStopaBindingSource_ListChanged);
				this.uxRazdobljeStopaBindingSource.CurrentItemChanged += new System.EventHandler(OnRazdobljeStopaBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnRazdobljeStopaBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentRazdobljeStopa = uxRazdobljeStopaBindingSource.Current as Entities.RazdobljeStopa;
			
			if (_currentRazdobljeStopa != null)
			{
				_currentRazdobljeStopa.Validate();
			}
			//_RazdobljeStopa.Validate();
			OnCurrentEntityChanged();
		}

		//void uxRazdobljeStopaBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.RazdobljeStopa"/> instance.
		/// </summary>
		public Entities.RazdobljeStopa SelectedRazdobljeStopa
		{
			get {return this._currentRazdobljeStopa;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxRazdobljeStopaDataGridView.VirtualMode;}
			set
			{
				this.uxRazdobljeStopaDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxRazdobljeStopaDataGridView.AllowUserToAddRows;}
			set {this.uxRazdobljeStopaDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxRazdobljeStopaDataGridView.AllowUserToDeleteRows;}
			set {this.uxRazdobljeStopaDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxRazdobljeStopaDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxRazdobljeStopaDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="RazdobljeStopaDataGridViewBase"/> class.
		/// </summary>
		public RazdobljeStopaDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxRazdobljeStopaDataGridView = new System.Windows.Forms.DataGridView();
			this.uxRazdobljeStopaBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxRazdobljeStopaErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIDDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxDatumOdDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxDatumDoDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxStopaDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			((System.ComponentModel.ISupportInitialize)(this.uxRazdobljeStopaDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxRazdobljeStopaBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxRazdobljeStopaErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxRazdobljeStopaErrorProvider
			// 
			this.uxRazdobljeStopaErrorProvider.ContainerControl = this;
			this.uxRazdobljeStopaErrorProvider.DataSource = this.uxRazdobljeStopaBindingSource;						
			// 
			// uxRazdobljeStopaDataGridView
			// 
			this.uxRazdobljeStopaDataGridView.AutoGenerateColumns = false;
			this.uxRazdobljeStopaDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxRazdobljeStopaDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIDDataGridViewColumn,
		this.uxDatumOdDataGridViewColumn,
		this.uxDatumDoDataGridViewColumn,
		this.uxStopaDataGridViewColumn			});
			this.uxRazdobljeStopaDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxRazdobljeStopaDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxRazdobljeStopaDataGridView.Name = "uxRazdobljeStopaDataGridView";
			this.uxRazdobljeStopaDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxRazdobljeStopaDataGridView.TabIndex = 0;	
			this.uxRazdobljeStopaDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxRazdobljeStopaDataGridView.EnableHeadersVisualStyles = false;
			this.uxRazdobljeStopaDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnRazdobljeStopaDataGridViewDataError);
			this.uxRazdobljeStopaDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnRazdobljeStopaDataGridViewCellValueNeeded);
			this.uxRazdobljeStopaDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnRazdobljeStopaDataGridViewCellValuePushed);
			
			//
			// uxIDDataGridViewColumn
			//
			this.uxIDDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDDataGridViewColumn.DataPropertyName = "ID";
			this.uxIDDataGridViewColumn.HeaderText = "ID";
			this.uxIDDataGridViewColumn.Name = "uxIDDataGridViewColumn";
			this.uxIDDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDDataGridViewColumn.ReadOnly = true;		
			//
			// uxDatumOdDataGridViewColumn
			//
			this.uxDatumOdDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxDatumOdDataGridViewColumn.DataPropertyName = "DatumOd";
			this.uxDatumOdDataGridViewColumn.HeaderText = "DatumOd";
			this.uxDatumOdDataGridViewColumn.Name = "uxDatumOdDataGridViewColumn";
			this.uxDatumOdDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxDatumOdDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxDatumOdDataGridViewColumn.ReadOnly = false;		
			//
			// uxDatumDoDataGridViewColumn
			//
			this.uxDatumDoDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxDatumDoDataGridViewColumn.DataPropertyName = "DatumDo";
			this.uxDatumDoDataGridViewColumn.HeaderText = "DatumDo";
			this.uxDatumDoDataGridViewColumn.Name = "uxDatumDoDataGridViewColumn";
			this.uxDatumDoDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxDatumDoDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxDatumDoDataGridViewColumn.ReadOnly = false;		
			//
			// uxStopaDataGridViewColumn
			//
			this.uxStopaDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxStopaDataGridViewColumn.DataPropertyName = "Stopa";
			this.uxStopaDataGridViewColumn.HeaderText = "Stopa";
			this.uxStopaDataGridViewColumn.Name = "uxStopaDataGridViewColumn";
			this.uxStopaDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxStopaDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxStopaDataGridViewColumn.ReadOnly = false;		
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxRazdobljeStopaDataGridView);
			this.Name = "RazdobljeStopaDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			((System.ComponentModel.ISupportInitialize)(this.uxRazdobljeStopaErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxRazdobljeStopaDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxRazdobljeStopaBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				RazdobljeStopaDataGridViewEventArgs args = new RazdobljeStopaDataGridViewEventArgs();
				args.RazdobljeStopa = _currentRazdobljeStopa;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class RazdobljeStopaDataGridViewEventArgs : System.EventArgs
		{
			private Entities.RazdobljeStopa	_RazdobljeStopa;
	
			/// <summary>
			/// the  Entities.RazdobljeStopa instance.
			/// </summary>
			public Entities.RazdobljeStopa RazdobljeStopa
			{
				get { return _RazdobljeStopa; }
				set { _RazdobljeStopa = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxRazdobljeStopaDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnRazdobljeStopaDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxRazdobljeStopaDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnRazdobljeStopaDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxRazdobljeStopaDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDataGridViewColumn":
						e.Value = RazdobljeStopaList[e.RowIndex].ID;
						break;
					case "uxDatumOdDataGridViewColumn":
						e.Value = RazdobljeStopaList[e.RowIndex].DatumOd;
						break;
					case "uxDatumDoDataGridViewColumn":
						e.Value = RazdobljeStopaList[e.RowIndex].DatumDo;
						break;
					case "uxStopaDataGridViewColumn":
						e.Value = RazdobljeStopaList[e.RowIndex].Stopa;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxRazdobljeStopaDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnRazdobljeStopaDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxRazdobljeStopaDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDataGridViewColumn":
						RazdobljeStopaList[e.RowIndex].ID = (System.Int32)e.Value;
						break;
					case "uxDatumOdDataGridViewColumn":
						RazdobljeStopaList[e.RowIndex].DatumOd = (System.DateTime)e.Value;
						break;
					case "uxDatumDoDataGridViewColumn":
						RazdobljeStopaList[e.RowIndex].DatumDo = (System.DateTime)e.Value;
						break;
					case "uxStopaDataGridViewColumn":
						RazdobljeStopaList[e.RowIndex].Stopa = (System.Double)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
